package com.example.util;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Map;

public class SecurityUtil {

    public static String getUsername(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String jsonString = JSONObject.toJSONString(principal);
        Map map = JSONObject.parseObject(jsonString, Map.class);
        return map.get("username").toString();
    }
}
